package com.ibpd.henuocms.test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Random;

import com.ibpd.dao.impl.ServiceProxyFactory;
import com.ibpd.henuocms.entity.PaperEntity;
import com.ibpd.henuocms.service.paper.IPaperService;
import com.ibpd.henuocms.service.paper.PaperServiceImpl;

public class test2 {

	/**
	 * @param args
	 * @throws InterruptedException 
	 * @throws SecurityException 
	 * @throws NoSuchMethodException 
	 * @throws InvocationTargetException 
	 * @throws IllegalArgumentException 
	 * @throws IllegalAccessException 
	 */
	public static void main(String[] args) throws InterruptedException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		
		IPaperService ps=(IPaperService) ServiceProxyFactory.getServiceProxy(PaperServiceImpl.class);
//		for(Integer i=0;i<10;i++){
//			PaperEntity p=new PaperEntity();
//			p.setPaperName("paperName"+i);
//			ps.saveEntity(p);
//		}
		list(ps);
//		list(ps);
//		list(ps);
//		list(ps);
//		list(ps);
//		list(ps);
//		list(ps);
//		list(ps);
//		list(ps);
//		list(ps);
		List<PaperEntity> pl = ps.getList();
		if(pl!=null){
			if(pl.size()>0){
				Method mthod=pl.get(0).getClass().getMethod("setPaperName", new Class[]{String.class});
				mthod.invoke(pl.get(0), "test99999");
				ps.saveEntity(pl.get(0));
			}
		}	
		list(ps);
		list(ps);
		list(ps);
		list(ps);
		list(ps);
		list(ps);
		list(ps);
		list(ps);
		list(ps);
		list(ps);
		list(ps);
		list(ps);
	}

	private static void list(IPaperService ps2) throws InterruptedException{
		IPaperService ps=(IPaperService) ServiceProxyFactory.getServiceProxy(PaperServiceImpl.class);
		Thread.sleep(new Random().nextInt(20000));
		System.out.println("============");
//		ps.getDao().clearCache();
		List<PaperEntity> pl2 = ps.getList();
		if(pl2!=null){
			if(pl2.size()>0){
					for(PaperEntity p:pl2)
						System.out.println(p.getPaperName());
			}
		}	

	}
}
